import { generatedRoutes } from './elegant/routes';
import { filterRoutes, getReactRoutes } from './routes';
import { BaseChildrenRoutes } from './routes/builtin';

/**
 * - 初始化路由
 * - 生成所有路由ex
 * - 生成权限路由
 * - 生成常量路由
 */
function initRoutes() {
  const customRoutes = getReactRoutes(generatedRoutes);

  const baseRoute = customRoutes[0]?.children?.find((route) => route.id === '(base)');

  baseRoute?.children?.push(...BaseChildrenRoutes);

  const authRoutes: Router.SingleAuthRoute[] = [];
  const cacheRoutes: string[] = [];
  const allRoutes = { ...customRoutes };
  const constantRoutes = filterRoutes(customRoutes, null, authRoutes, cacheRoutes);

  return { allRoutes, authRoutes, cacheRoutes, routes: constantRoutes };
}

export const { allRoutes, authRoutes, cacheRoutes: initCacheRoutes, routes } = initRoutes();
